# encoding    : utf-8
# author      : 伦裕如
# project     : hrjt_-py1
# file        : code2
# time        : 2024-06-21 上午9:48 

import openpyxl

# 连接 excel 表
wb = openpyxl.load_workbook('test.xlsx')

# 获取或创建工作表
sheets = wb.sheetnames
if '1234' in sheets:
    sheet = wb['1234']
else:
    sheet = wb.create_sheet('1234')

# 向表中写入乘法口诀表
for i in range(1, 10):
    for j in range(1, i + 1):
        sheet.cell(row = i, column = j).value = f'{i} * {j} = {i * j}'

# 打印表中所有单元格数据
for i in range(1, 10):
    for j in range(1, i + 1):
        print(sheet.cell(row = i, column = j).value, end = '\t')
    print()
wb.save('test.xlsx')


